package com.edu.interceptor;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @Author:zyn
 * @Date:2025/11/11--9:54:54
 */
public class MyInterceptor implements MethodInterceptor {
    private Object target;

    public MyInterceptor(Object o){
        this.target=o;
    }
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        long start=System.currentTimeMillis();
        Object result=method.invoke(target,objects);
        Thread.sleep(3000);
        long end=System.currentTimeMillis();
        System.out.println(method.getName()+"()方法执行耗时："+(end-start));
        return result;
    }
}
